package com.example.gbasedemo.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gbasedemo.mapper.TradeBaseDetailMapper;
import com.example.gbasedemo.mapper.TradeBaseDetailPojo;
import com.example.gbasedemo.mapper.TradeBaseMapper;
import com.example.gbasedemo.mapper.TradeBasePojo;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Service
public class ServiceTradeBaseDetail extends ServiceImpl<TradeBaseDetailMapper, TradeBaseDetailPojo> {

    public void createTable() {
        baseMapper.createTable();
    }

    public void insert() {
        TradeBaseDetailPojo pojo = getPojo(1);
        baseMapper.insert(pojo);
    }

    public void updateRow() {
        TradeBaseDetailPojo pojo = getPojo(1);
        pojo.setExt_3("ext33333333333");
        baseMapper.updateById(pojo);
    }

    public void deleteRow() {
        baseMapper.deleteById(1);
    }

    public TradeBaseDetailPojo selectRow() {
        return baseMapper.selectById(1);
    }

    public void insertRows() {
        List<TradeBaseDetailPojo> rows = new ArrayList<>();
        for (int i=1; i<=2; i++) {
            TradeBaseDetailPojo pojo = getPojo(i);
            rows.add(pojo);
        }
        baseMapper.insertRows(rows);
    }

    private TradeBaseDetailPojo getPojo(int index) {
        TradeBaseDetailPojo pojo = new TradeBaseDetailPojo();
        pojo.setId(index);
        pojo.setFiled_a(index * 10);
        pojo.setFiled_b(index * 10);
        pojo.setFiled_c(index + "v filed_c");
        pojo.setFiled_d(index + "v filed_d");
        pojo.setFiled_f(index + "v filed_f");
        pojo.setFiled_g(index + "v filed_g");
        pojo.setFiled_h(index + "v filed_h");
        pojo.setFiled_i(index + "v filed_i");
        pojo.setYn(index * 100);
        pojo.setCreate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setUpdate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setExt_1(index + "ext 1");
        pojo.setExt_2(index + "12ext 2");
        pojo.setExt_3(index + "12ext 3");
        return pojo;
    }

}
